<template>
	<view class="page">
			<view class="searchBox">
				<view class="inputBox">
					
				<!-- 	<view class="inputRow">
						<view class="label">
							{{'餐段'}}:
						</view>
						<view :class="params.mealName ? 'val' : 'emty'" @click="selectShow=true">
							{{mealName ? mealName : language.consumeRecord.tip }}
						</view>
					</view> -->
					<view class="inputRow">
						<view class="label">
							{{language.consumeRecord.label1}}:
						</view>
						<view :class="params.diningDay_begin ? 'val' : 'emty'" @click="diningDay_beginShow=true">
							{{params.diningDay_begin ? params.diningDay_begin : language.consumeRecord.tip }}
						</view>
					</view>
					<view class="inputRow">
							<view class="label">
								{{language.consumeRecord.label2}}:
							</view>
							<view :class="params.diningDay_end ? 'val' : 'emty'" @click="diningDay_endShow=true">
								{{params.diningDay_end ? params.diningDay_end : language.consumeRecord.tip }}
							</view>
					</view>
				</view>
				<view class="btnBox">
					<view class="btn"  @click="goSearch">
						{{language.consumeRecord.search}}
					</view>
				</view>
			</view>
			<u-subsection :list="selectList" :current="current"  @change="sectionChange"></u-subsection>
			<scrollYBox styleText="height: calc( 100vh - 320rpx ) ;" @scrolltolower="scrolltolower" :list="list">
						<template>
							<view style="padding-bottom: 50rpx;">
								<view class="boxItem" v-for="(item,index) in list" :key="index">
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{'餐段：'}}
											</view>
											<view class="val">
												{{item.mealName }}
											</view>
										</view>
									</view>
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{'就餐日：'}}
											</view>
											<view class="val">
												{{item.diningDay }}
											</view>
										</view>
										<view class="btn" style="background: #f5bd00;" v-if="!current" @click="handleReturn(item.id)">
											{{'停餐'}}
										</view>
										<view class="btn" style="background: #0072e5;" v-if="current" @click="handleReturn(item.id)">
											{{'撤销停餐'}}
										</view>
									</view>
								</view>
							</view>
						</template>
			</scrollYBox>
			<u-datetime-picker
			    :show="diningDay_beginShow" ref="datetimePicker" v-model="diningDay_begin" 
			    mode="date"  @cancel="diningDay_beginShow=false" @confirm="diningDay_beginConfirm"
			       ></u-datetime-picker>
			<u-datetime-picker
				:show="diningDay_endShow" ref="datetimePicker" v-model="diningDay_end" 
				mode="date"  @cancel="diningDay_endShow=false" @confirm="diningDay_endConfirm"
			   ></u-datetime-picker>
			<u-picker :show="selectShow" :columns="mealList" keyName="label" @confirm="selectConfirm"
				@cancel="selectShow = false"></u-picker>
	</view>
</template>

<script>
	import { csMealsOrderListApi,applyForRefundApi,csMealsProductListApi} from '@/common/api/commonApi/bookingMeal.js'
	export default {
		data() {
			return {
				list:[],
				params:{
					pageNo:1,
					pageSize: 10,
					diningDay_begin : '',
					diningDay_end : '',
					// mealName : '',
				},
				mealName: '',
				diningDay_begin: Number(new Date()),
				diningDay_end: Number(new Date()),
				diningDay_beginShow : false,
				diningDay_endShow : false,
				total : 0,
				isTeacher: 2,
				auditObj:{},
				auditShow: false,
				auditList: [{
						name: '是',
						value: 1
					},
					{
						name: '否',
						value: 2,
					},
				],
				auditValue: 1,
				auditOpinion:'',
				selectList:[
					'正常',
					/* '待审批', */
					'已停餐',
				],
				mealList : [
					[
						// {
						// 	label:'早餐',
						// 	value: '1'
						// },
						// {
						// 	label:'午餐',
						// 	value: '2'
						// },
						// {
						// 	label:'晚餐',
						// 	value: '3'
						// },
					]
				],
				selectShow: false,
				current:0,
				isTeacher: 2,
			}
		},
		components:{
		},
		methods: {
			getMealList(){
				return csMealsProductListApi({
					status : 1,
				}).then(res=>{
					this.mealList[0] = []
					res.result.records.forEach(item=>{
						this.mealList[0].push({
								label: item.mealName,
								value: item.mealName
						})
					})
					
				})
			},
			selectConfirm(e){
				console.log(e);
				this.mealName = e.value[0].label
				this.params.mealName = e.value[0].value
				this.selectShow = false
			},
			diningDay_beginConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.diningDay_begin = date
				console.log(this.params.diningDay_begin);
				this.diningDay_beginShow = false
			},
			diningDay_endConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.diningDay_end = date
				this.diningDay_endShow = false
			},
			sectionChange(index){
				this.current = index
				this.goSearch()
			},
			handleReturn(id){
				uni.showModal({
					content:'是否提交该操作',
					success: (res) => {
						if(res.confirm){
							applyForRefundApi({
								id,
							}).then(res=>{
								this.setMessage('操作成功')
								this.goSearch()
							})
						}
					}
				})
			},
			scrolltolower(){
				if(this.total == this.list.length){
					return this.setMessage('没有更多了')
				}
				this.params.pageNo ++
				this.getList()
			},
			goSearch(){
				if(this.params.diningDay_begin && this.params.diningDay_end ){
					if(new Date(this.params.diningDay_begin) > new Date(this.params.diningDay_end) ) return this.setMessage('开始时间不能大于结束时间')
				}
				this.params.pageNo = 1 
				this.getList()
			},
			getList(){
				let params = this.params
				if(!params.diningDay_end) delete params.diningDay_end
				if(!params.diningDay_begin) delete params.diningDay_begin
				// if(this.isTeacher==1)
				 params.status = this.current+1
				return csMealsOrderListApi(params).then(res=>{
					if(params.pageNo==1) this.list = []
					this.list = this.list.concat(res.result.records)
					this.total = res.result.total
				})
			},
		},
		onLoad({isTeacher}) {
			if(isTeacher) this.isTeacher = isTeacher
			this.getMealList()
		},
		onShow() {
			this.goSearch()
		},
	}
</script>

<style lang="scss" scoped>
	.searchRow{
			background-color: #fff;
			display: flex;
			align-items: center;
			padding: 0rpx 20rpx 0 20rpx;
			border-bottom: 2rpx solid #dedede;
			height: 140rpx;
			margin: 20rpx;
			.leftBox{
				flex: 1;
				.row{
					display: flex;
					align-items: center;
					height: 70rpx;
					padding-left: 20rpx;
					.label{
						color: #000000d9;
						margin-right: 30rpx;
					}
					.val{
						color: #595959;
					}
				}
			}
			.btn{
				width: 140rpx;
				height: 56rpx;
				border-radius: 10rpx;
				color: #fff;
				@include flexCenter;
				background-color: #4089f0;
			}
			
	}
	
	
.page{
	background-color: #f1f1f1;
	// height: 100vh;
	.searchBox{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 0 20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin: 20rpx;
		border-radius: 8rpx;
		box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
		.inputBox{
			flex: 1;
			padding-right: 30rpx;
			.inputRow{
				height: 80rpx;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				padding-left: 20rpx;
				.label{
					color: #191919;
					margin-right: 30rpx;
				}
			}
			.input{
				
			}
			.emty{
				color: #c0c4cc;
			}
			.val{
				
			}
		}
		.btnBox{
			display: flex;
			flex-direction: column;
			padding: 10rpx 0;
			.reset{
				margin-top: 20rpx;
				border: 1px solid #f1f1f1;
				background: #fff !important;
				color: #353535 !important;
			}
			.btn{
				padding: 0 30rpx;
				// width: 110rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #1890ff;
				border-radius: 8rpx;
				color: #fff;
			}
		}
	}
	
	.boxItem{
			background-color: #fff;
			margin: 20rpx;
			border-radius: 8rpx;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(102,102,102,0.15);
			.row{
				margin: 10rpx;
				display: flex;
				.item{
					// padding-left: 10rpx;
					// width: 50%;
					flex: 1;
					display: flex;
				}
				.label{
					color: #969696;
				}
				.val{
					color: #353535;
					font-size: 32rpx;
				}
				.btn{
						padding: 0 30rpx;
						// width: 120rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: #1890ff;
						border-radius: 8rpx;
						color: #fff;
						margin-right: 10rpx;
				}
			}
		}
		
}
</style>
